<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>雪月蛋糕</title>
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="../../img/favicon.ico" type="image/x-icon">

</head>

<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black">
            <i class="layui-icon" style="font-size: 30px; color: white;"></i>
            雪月蛋糕管理系统
        </div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                <a href="javascript:;">
                    <img src="../../img/1.jpg" class="layui-nav-img">
                    <span id="user_show_name"></span>
                </a>
                <dl class="layui-nav-child">
                    <dd><a id="logout">退出登录</a></dd>
                </dl>
            </li>
        </ul>
    </div>
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul id="nav" class="layui-nav layui-nav-tree" lay-filter="test">
                <script id="menu_tmpl" type="text/html">
                    {{#  layui.each(d.menus, function(index, item){}}
                    <li class="layui-nav-item">
                        <a url-data="{{=item.url}}" href="javascript:;">
                            <i class="layui-icon {{=item.icon}}" style="font-size: 20px; color: white;"></i>
                            {{=item.title}}
                        </a>
                    </li>
                    {{#  }); }}
                </script>
            </ul>
        </div>
    </div>
    <div class="layui-body">
        <div id="main" style="padding: 15px;"></div>
    </div>
</div>

<script src="../../layui/layui.js"></script>
<script>

    //JS
    layui.use(['element', 'layer', 'util'], function () {
        var element = layui.element;
        var layer = layui.layer;
        var util = layui.util;
        var laytpl = layui.laytpl;
        var $ = layui.$;

        $.ajax({
            url:"/main/init",
            success:function (res) {
                $("#user_show_name").text(res.showName);
                var getTpl = $("#menu_tmpl").html();
                laytpl(getTpl).render(res, function (str) {
                    $("#nav").html(str);
                    $("#nav a[url-data]:first").click();
                });
            },
            error:function(){
                layer.alert("请先登录后再访问",{
                    title:"错误信息",
                    icon:2
                },function (){
                    location.href="/html/login.html";
                });
            }
        });


        $("#logout").click(function () {
            var loadIndex = layer.load(2);
            $.get("/admin/logout", function () {
                location.href = "../login.html";
                layer.close(loadIndex)
            });
        });

        $("#nav").on("click", "a[url-data]", function (e) {
            $("#nav li").removeClass("layui-this");
            $("#main").load($(e.target).attr("url-data"));
            $(e.target.parentNode).addClass("layui-this");
        });

    });
</script>
</body>

</html>